package okl.lab.namesFilter.tests.utils
{
	import okl.lab.namesFilter.model.vo.User;

	/**
	 * Provides for testing/mocking purposes.
	 * Static class based on ObjectMother pattern.
	 * 
	 *	@author "oleksandr.kulinchenko@gmail.com"
	 */
	/*static*/public class TestDataGenerator
	{
		private static var maleFirstNames:Array=["John", "Alex", "Danny", "Igor", "Anthony", "Josh", "Freddy" ];
		private static var femaleFirstNames:Array=["MARY", "Natali", "Linda"];
		private static var lastNames:Array=["Braun", "Jones", "Zeddy", "Smith", "Ali", "Chan", "Crouger", "Lector", "Brigs", "Cash"];
		
		public static function generateUsers(count:Number=10):Array/*<User>*/{
			var result:Array = new Array();
			for(var i:uint=0;i<count; i++){
				result.push(generateUser());					
			}
			return result;
		}
		
		public static function createUser(firstName:String, lastName:String, female:Boolean=false):User{
			var newUser:User = new User();
			newUser.firstName = firstName;
			newUser.lastName = lastName;
			newUser.female = female;
			return newUser;
		}
		
		private static function generateUser():User{
			var newUser:User = new User();
			newUser.lastName = _getRandomElement(lastNames) as String;
			newUser.female = (Math.random()<0.3); //small probability
			var firstNames:Array = (newUser.female) ? femaleFirstNames : maleFirstNames;
			newUser.firstName = _getRandomElement(firstNames) as String;
			return newUser;
		}
		
		private static function _getRandomElement(arr:Array):Object{
			if(arr==null)return null;
			var targetIndex:Number= Math.round(Math.random() * (arr.length-1));
			return arr[targetIndex];
		}
	
	}
}